<template>
  <div class="sigin">
    <header>
      <van-icon name="arrow-left" @click="$router.go(-1)" />
      <p>您的可用积分为</p>
      <b>{{ result[0]?.scoreLeft }}</b>
    </header>
    <div class="center">连续签到{{ result[0]?.score }}天</div>
    <button class="sigin_btn" @click="add">签到</button>
    <ul>
      <li>
        <img src="../../assets/img/shopping.jpeg" alt="" />
        <section>
          <p>消费购物</p>
          <p>购物完成，确认收货后立返积分</p>
        </section>
        <span>去购物</span>
      </li>
      <li>
        <img src="../../assets/img/money.jpeg" alt="" />
        <section>
          <p>积分兑换</p>
          <p>积分兑好礼，20积分即可兑换礼券</p>
        </section>
        <span>去兑换</span>
      </li>
    </ul>
  </div>
</template>

<script>
import { ref, reactive, toRefs } from "vue";
import { getLogs } from "../../api/home/home";
import { addSign } from "../../api/second/index";
import { Notify } from 'vant';
export default {
  setup() {
    const data = reactive({
      result: [], // 签到的列表
    });
    const info = () => {
      getLogs({ token: localStorage.getItem("token") }).then((res) => {
        data.result = res.data.result;
      });
    };
    info(); // 进入页面调用这个函数
    const add = () => {
      addSign({ token: localStorage.getItem("token") }).then((res) => {
        if (res.code == 0) {
            info();
            Notify({ type: 'success', message: '签到成功' });
        } else {
            Notify({ type: 'danger', message: res.msg });
        }
      });
    };
    return {
      ...toRefs(data),
      add,
    };
  },
};
</script>
<style lang="scss" scoped>
header {
  height: 224px;
  background: -webkit-gradient(
    linear,
    left top,
    right top,
    from(#f1ead8),
    to(#fefbf2)
  );
  overflow: hidden;
  text-align: center;
  p {
    color: #aeaeab;
    font-size: 14px;
    text-align: center;
    margin: 80px auto 40px;
  }
  b {
    color: #b3a078;
  }
}
.van-icon-arrow-left {
  margin: 20px 0 0 10px;
  float: left;
}
.center {
  height: 65px;
  line-height: 65px;
  text-align: center;
  color: #fff;
  font-size: 16px;
  background: #e8e1cf;
}
.sigin_btn {
  font-size: 14px;
  color: #fff;
  border: none;
  width: 159px;
  line-height: 35px;
  text-align: center;
  border-radius: 18px;
  background: #b3a078;
  margin: 20px auto;
  display: block;
}
ul {
  padding: 0 10px;
}
li {
  height: 80px;
  display: flex;
  font-size: 12px;
  align-items: center;
  background: #f4ebe2;
  border-radius: 10px;
  margin-top: 10px;
  padding: 0 10px;
  img {
    height: 100%;
  }
  section {
    flex: 1;
    p {
      margin-top: 20px;
      color: #e1b68c;
    }
  }
  span {
    color: #fff;
    background: #e1b68c;
    border-radius: 5px;
    height: 23px;
    line-height: 23px;
    width: 46px;
    text-align: center;
  }
}
li:last-child {
  background: #ede6d6;
  section p {
    color: #b3a078;
  }
}
</style>